package com.ymatou.iapi.notify.testcase;

import com.ymatou.iapi.notify.parameter.CleanNotifyByIdBean;
import com.ymatou.iapi.notify.parameter.SendNotifyBean;
import com.ymatou.iapi.notify.service.CleanNotifyByIdCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.NotifyCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.Map;

/**
*删除通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CleanNotifyById{
	private static CleanNotifyByIdBean cleannotifybyidBean;
	private static CleanNotifyByIdCall cleannotifybyidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除通知");
	}

	@Before
	public void caseUp() {
		cleannotifybyidBean=new CleanNotifyByIdBean();
		cleannotifybyidCall=new CleanNotifyByIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cleannotifybyidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CleanNotifyById_01() {
		Logger.start(true,"删除通知");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int sendId = 30156393;
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(sendId,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			cleannotifybyidBean.setSenderId(sendNotifyBean.getNotifySenderUserId());
			cleannotifybyidBean.setUserId(sendNotifyBean.getToUserId());
			cleannotifybyidCall.setData(cleannotifybyidBean);
			cleannotifybyidCall.callService();			
			Logger.verifyEquals("Success",cleannotifybyidCall.getString("Status"),"验证Status");
			Map map = new ImDefaultWapper().selectImNotifyByToUserId(userId).get(0);
			Logger.verifyEquals(1,Integer.parseInt(map.get("IsDelete").toString()),"验证数据库数据");
			//未读数清零
			Logger.verifyEquals(0,Integer.parseInt(map.get("IsRead").toString()),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CleanNotifyById_02() {
		Logger.start(true,"删除通知,userId不存在");
		try {
			int sendId = 30156393;
			cleannotifybyidBean.setSenderId(sendId);
			cleannotifybyidBean.setUserId(0);
			cleannotifybyidCall.setData(cleannotifybyidBean);
			cleannotifybyidCall.callService();
			Logger.verifyEquals("BussinessError",cleannotifybyidCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}